package com.yc.auction.actions;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.yc.auction.dao.IUsersDao;
import com.yc.auction.dao.impl.UsersDaoImpl;
import com.yc.auction.entity.JsonObject;
import com.yc.auction.entity.Users;

@SuppressWarnings("serial")
public class UsersAction extends ActionSupport{
	private Users users;
	private JsonObject jsonObject;
	private UsersDaoImpl userDao=new UsersDaoImpl();
	
	public JsonObject getJsonObject() {
		return jsonObject;
	}

	public void setJsonObject(JsonObject jsonObject) {
		this.jsonObject = jsonObject;
	}

	public Users getUsers() {
		return users;
	}

	public void setUsers(Users users) {
		this.users = users;
	}
	
	/**
	 * 用户注册
	 * @return
	 */
	public String addUsers(){
		int result=0;
		if(users!=null){
			users.setUsid(1);
			result=userDao.add(users);
		}
		jsonObject=new JsonObject<Object>();
		jsonObject.setResult(result);
		return "success";
	}
	
	/**
	 * 用户登录
	 * @return
	 */
	public String login(){
		Users user=userDao.login(users);
		if(user!=null){
			HttpSession session=ServletActionContext.getRequest().getSession();
			session.setAttribute("currentUser", user);
			return "success";
		}else{
			return "login";
		}
	}
	
}
